home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2007 September
/
PCWSEP07.iso
/
Software
/
Resources
/
Internet
/
BadBlue PE 2.7
/
bb98.exe
/
SOhttp.php
< prev
next >
Wrap
PHP Script
|
2002-06-25
|
2KB
|
81 lines
<?php if (!defined("SOhttp")) { define("SOhttp", 1);
// Retrieve a web page.
// Inputs:
// $sURL: full URL of page to retrieve
// $sPage: returned page if successful
// $sUser: (optional) user to authenticate as
// $sPassword: (optional) password to authenticate as
// Outputs:
// $errmsg: empty if no error occurred, otherwise error message
//
function SOHTTPGet($sURL, &$sPage, $sUser = "", $sPassword = "") {
$errmsg = "";
$sPage = "";
do {
// Strip off prefix and port.
//
if (!(($nCursor = strpos($sURL, "http://")) === false)) {
$sURL = substr($sURL, 7);
}
if (($nCursor = strpos($sURL, '/')) > 0) {
$sServer = substr($sURL, 0, $nCursor);
$sURL = substr($sURL, $nCursor);
} else {
$sServer = $sURL;
$sURL = "/";
}
if (($nCursor = strpos($sServer, ':')) > 0) {
$nPort = substr($sServer, $nCursor + 1, 5);
// $nPort = settype($nPort, "integer");
$sServer = substr($sServer, 0, $nCursor);
} else {
$nPort = 80;
}
// Grab the page if we can...
//
$fp = fsockopen($sServer, $nPort, $nErr, $errmsg, 30);
if (!$fp) {
break;
}
if (strlen($sUser)) {
$sCreds = "Authorization: Basic ".base64_encode($sUser.":".$sPassword)."\r\n";
} else {
$sCreds = "";
}
$sReq =
"GET ".$sURL." HTTP/1.0\r\n".
"User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)\r\n".
"Accept-Encoding: none\r\n".
"Accept-Language: en-us,fr-be;q=0.5\r\n".
"Pragma: No-Cache\r\n".
"Host: ".$sServer."\r\n".
"Accept: */*\r\n".
$sCreds.
"\r\n";
fputs($fp, $sReq);
for ($i = 0; !feof($fp); $i++) {
$sTemp = fgets($fp, 16384);
if (!$i) {
$nTemp = 555;
if (($nCursor = strpos($sTemp, ' ')) > 0) {
$nTemp = intval(substr($sTemp, $nCursor + 1));
}
if ($nTemp != 200) {
$errmsg = substr($sTemp, $nCursor + 1);
break;
}
}
$sPage .= $sTemp;
}
fclose($fp);
//
} while (0);
return ($errmsg);
}
} ?>